import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Layout',
    component: () => import('@/layout/index.vue'),
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: {
          title: '仪表盘',
          icon: 'Odometer'
        }
      },
      {
        path: '/data-sync',
        name: 'DataSync',
        component: () => import('@/views/data-sync/index.vue'),
        meta: {
          title: '数据同步',
          icon: 'Connection'
        }
      },
      {
        path: '/data-sync/create',
        name: 'DataSyncCreate',
        component: () => import('@/views/data-sync/create.vue'),
        meta: {
          title: '创建同步任务',
          icon: 'Plus',
          hidden: true
        }
      },
      {
        path: '/data-sync/edit/:id',
        name: 'DataSyncEdit',
        component: () => import('@/views/data-sync/edit.vue'),
        meta: {
          title: '编辑同步任务',
          icon: 'Edit',
          hidden: true
        }
      },
      {
        path: '/etl-development',
        name: 'ETLDevelopment',
        component: () => import('@/views/etl-development/index.vue'),
        meta: {
          title: 'ETL 开发',
          icon: 'Setting'
        }
      },
      {
        path: '/etl-development/create',
        name: 'ETLDevelopmentCreate',
        component: () => import('@/views/etl-development/create.vue'),
        meta: {
          title: '创建 ETL 任务',
          icon: 'Plus',
          hidden: true
        }
      },
      {
        path: '/workflow-scheduler',
        name: 'WorkflowScheduler',
        component: () => import('@/views/workflow-scheduler/index.vue'),
        meta: {
          title: '任务调度',
          icon: 'Timer'
        }
      },
      {
        path: '/workflow-scheduler/create',
        name: 'WorkflowCreate',
        component: () => import('@/views/workflow-scheduler/create.vue'),
        meta: {
          title: '创建工作流',
          icon: 'Plus',
          hidden: true
        }
      },
      {
        path: '/workflow-scheduler/edit/:id',
        name: 'WorkflowEdit',
        component: () => import('@/views/workflow-scheduler/edit.vue'),
        meta: {
          title: '编辑工作流',
          icon: 'Edit',
          hidden: true
        }
      },
      {
        path: '/data-map',
        name: 'DataMap',
        component: () => import('@/views/data-map/index.vue'),
        meta: {
          title: '数据地图',
          icon: 'MapLocation'
        }
      },
      {
        path: '/data-map/lineage/:tableId',
        name: 'DataLineage',
        component: () => import('@/views/data-map/lineage.vue'),
        meta: {
          title: '数据血缘',
          icon: 'Share',
          hidden: true
        }
      },
      {
        path: '/data-sources',
        name: 'DataSources',
        component: () => import('@/views/data-sources/index.vue'),
        meta: {
          title: '数据源管理',
          icon: 'Coin'
        }
      },
      {
        path: '/datawarehouse-config',
        name: 'DatawarehouseConfig',
        component: () => import('@/views/datawarehouse-config/index.vue'),
        meta: {
          title: '数据仓库配置',
          icon: 'Operation'
        }
      },
      {
        path: '/api-services',
        name: 'ApiServices',
        component: () => import('@/views/api-services/index.vue'),
        meta: {
          title: 'API 服务',
          icon: 'Link'
        }
      },
      {
        path: '/script-development',
        name: 'ScriptDevelopment',
        component: () => import('@/views/script-development/index.vue'),
        meta: {
          title: '脚本开发',
          icon: 'Document'
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录'
    }
  },
  // 捕获所有未匹配的路由，重定向到仪表盘
  {
    path: '/:pathMatch(.*)*',
    redirect: '/dashboard'
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 添加路由守卫用于调试
router.beforeEach((to, from, next) => {
  console.log('路由跳转:', from.path, '->', to.path)
  next()
})

export default router 